<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for internet
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
 * 
 * Licensed under the terms of the GNU Lesser General Public License:
 * 		http://www.opensource.org/licenses/lgpl-license.php
 * 
 * For further information visit:
 * 		http://www.fckeditor.net/
 * 
 * "Support Open Source software. What about a donation today?"
 * 
 * File Name: frmresourceslist.html
 * 	This page shows all resources available in a folder in the File Browser.
 * 
 * File Authors:
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<link href="browser.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript" src="js/fckxml.js"></script>
<style>
TABLE TR.odd {
	BACKGROUND-COLOR:#CFE1FE; TEXT-ALIGN: left
}
TABLE TR.even {
	BACKGROUND-COLOR:#FEE7EB; TEXT-ALIGN: left
}
A:link {
	FONT-WEIGHT: bold; COLOR:#0033CC; TEXT-DECORATION: none
}
A:visited {
	FONT-WEIGHT: bold; COLOR: #696ab5; TEXT-DECORATION: none
}
A:active {
	FONT-WEIGHT: bold; COLOR: #696ab5; TEXT-DECORATION: none
}
A:hover {
	COLOR:#FF0000; TEXT-DECORATION: none
}
</style>
<script type="text/javascript">
function openImage(vLink, vHeight, vWidth)
{	
	winDef = 'status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,fullscreen=yes,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	newwin = open('', '_blank', winDef);
// new window
	newwin.document.writeln('<title>Picture</title>');
	newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" align="center">');
	newwin.document.writeln('	<table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">');
	newwin.document.writeln('		<tr align="center" valign="middle">');
	newwin.document.writeln('			<td align="center" valign="middle">');
	newwin.document.writeln('				<a href="" onClick="window.close(); return false;">');
	newwin.document.writeln('					<img src="'+ vLink+ '" border=0 align="center">');
	newwin.document.writeln('				</a>');
	newwin.document.writeln('			</td>');
	newwin.document.writeln('		</tr>');
	newwin.document.writeln('	</table>');
	newwin.document.writeln('</body>');
}



var oListManager = new Object() ;

oListManager.Clear = function()
{
	document.body.innerHTML = '' ;
}

oListManager.GetFolderRowHtml = function( folderName, folderPath, classStyle)
{
	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFolder(\'' + folderPath.replace( /'/g, '\\\'') + '\');return false;">' ;

	return '<tr class="' + classStyle + '">' +
			'<td width="16">' +
				sLink +
				'<img alt="" src="images/Folder.gif" width="16" height="16" border="0"></a>' +
			'</td>' +
			'<td nowrap colspan="5">&nbsp;' +
				sLink + 
				folderName + 
				'</a>' +
			'</td>' +
		'</tr>' ;
}

oListManager.GetFileRowHtml = function( fileName, fileUrl, fileSize, classStyle)
{
	// Build the link to view the folder.
	var sLink = '<a href="#" onclick="OpenFile(\'' + fileUrl.replace( /'/g, '\\\'') + '\');return false;">' ;

	// Get the file icon.
	var sIcon = oIcons.GetIcon( fileName ) ;
// phuong them
	str = fileName.substring(fileName.lastIndexOf('.'),fileName.length);
	if ((str == '.gif') || (str == '.jpg') || (str == '.png') || (str == '.bmp'))
	{
		stringImage = '<td><img alt="" src="' + fileUrl.replace( /'/g, '\\\'') + '" width="100" border="0"></td>'
	}
	else
		stringImage = '<td></td>';
// end phuong them
	return '<tr class="' + classStyle + '">' +
			'<td width="16">' +
				sLink + 
				'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"></a>' +
			'</td>' +
			'<td>&nbsp;' +
				sLink + 
				fileName + 
				'</a>' +
			'</td>' + stringImage +
			'<td align="right" nowrap>&nbsp;' +
				fileSize + 
				' KB' +
			'</td>' +
// phuong them
			//show
			'<td align="right" width="20">' +
				'<a href="javascript:confirmShow(\'' + fileUrl.replace( /'/g, '\\\'') +'\')">' +
					'<img alt="View File" border="0" src="images/view.gif" onClick="" style="cursor:pointer">' +
				'</a>' +
			'</td>' +
			//delete file
			'<td align="right" width="20">' +
				'<a href="javascript:confirmDelete(\'' + fileUrl.replace( /'/g, '\\\'') +'\')">' +
					'<img alt="Delete File" border="0" src="images/deleteFile.gif" onClick="" style="cursor:pointer">' +
				'</a>' +
			'</td>' +
// end phuong them
		'</tr>' ;
}
// phuong them
function confirmDelete(FileDelete)
{
	if(confirm('Are you sure you want to delete file "' + FileDelete + '"')==1)
	{
		var oXML = new FCKXml() ;
		oXML.LoadUrl( 'connectors/php/deleteFile.php?FileDelete=' + FileDelete, callBackFunction ) ;
	}
}
function confirmShow(FileRename)
{
		openImage(FileRename, 400, 300)
}
function callBackFunction()
{
	Refresh();
}
// end phuong them

function OpenFolder( folderPath )
{
	// Load the resources list for this folder.
	window.parent.frames['frmFolders'].LoadFolders( folderPath ) ;
}

function OpenFile( fileUrl )
{
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

function LoadResources( resourceType, folderPath )
{
	oListManager.Clear() ;
	oConnector.ResourceType = resourceType ;
	oConnector.CurrentFolder = folderPath
	oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
}

function Refresh()
{
	LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
}

function GetFoldersAndFilesCallBack( fckXml )
{
	if ( oConnector.CheckError( fckXml ) != 0 )
		return ;

//	var dTimer = new Date() ;

	// Get the current folder path.
	var oNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
	var sCurrentFolderPath	= oNode.attributes.getNamedItem('path').value ;
	var sCurrentFolderUrl	= oNode.attributes.getNamedItem('url').value ;
	
	var sHTML = '<table id="tableFiles" cellspacing="2" cellpadding="2" width="100%" border="0">' ;

	Dem=1;
	// Add the Folders.	
	var oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
	for ( var i = 0 ; i < oNodes.length ; i++ )
	{
		StyleClass=((Dem%2) != 0)? 'odd' : 'even';
		var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
		sHTML += oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" , StyleClass) ;
		Dem++;
	}

	// Add the Files.	
	var oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
	for ( var i = 0 ; i < oNodes.length ; i++ )
	{
		StyleClass=((Dem%2) != 0)? 'odd' : 'even';
		var sFileName = oNodes[i].attributes.getNamedItem('name').value ;
		var sFileSize = oNodes[i].attributes.getNamedItem('size').value ;
		sHTML += oListManager.GetFileRowHtml( sFileName, sCurrentFolderUrl + sFileName, sFileSize , StyleClass) ;
		Dem++;
	}

	sHTML += '</table>' ;

	document.body.innerHTML = sHTML ;

//	window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;
}

window.onload = function()
{
	window.top.IsLoadedResourcesList = true ;
}
	</script>
</head>
<body class="FileArea" bottommargin="10" leftmargin="10" topmargin="10" rightmargin="10">
</body>
</html>
